package com.bluemson.service.Impl;

import com.bluemson.dao.ManagerDao;
import com.bluemson.dao.UserDao;
import com.bluemson.entity.Article;
import com.bluemson.entity.Concern;
import com.bluemson.entity.Plate;
import com.bluemson.entity.User;
import com.bluemson.service.CheckService;
import com.bluemson.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

public class CheckServiceImpl implements CheckService {
    private final SqlSession session = MyBatisUtil.getSqlSession();
    UserDao userDao = session.getMapper(UserDao.class);
    @Override
    public User checkLogin(User user){
        User user1 = userDao.checkUser(user);
        if(user1!=null){
            userDao.loginStatus(user.getUsername());
            session.commit();
        }
        return user1;
    }
    @Override
    public void exitLogin(User user){
        userDao.exitStatus(user);
        session.commit();
    }
    @Override
    public boolean checkHost(String username){
        ManagerDao managerDao = session.getMapper(ManagerDao.class);
        Plate plate = managerDao.checkHost(username);
        return plate == null;
    }
    @Override
    public boolean checkConcern(Concern concern){
        return userDao.checkConcern(concern) == null;
    }
    @Override
    public boolean checkLike(Article article){
        return userDao.checkLike(article)==null;
    }
}
